package com.snail.billing.data;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

public class Account {

	public static final String TYPE_COMMON = "0";
	public static final String TYPE_RANDOM = "1";
	public static final String TYPE_MOBILE = "2";
	public static final String TYPE_RANDOM_OLD = "3";
	public static final String TYPE_FACEBOOK= "10";
	public static final String TYPE_GOOGLE = "11";
	
	private String account = "";
	private String pwd = "";
	private String type = "";

	public Account() {
	}

	public Account(String jsonString) {
		try {
			JSONObject json = new JSONObject(jsonString);
			if (json.has("account")) {
				account = json.getString("account");
			}
			if (json.has("pwd")) {
				pwd = json.getString("pwd");
			}
			if (json.has("type")) {
				type = json.getString("type");
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String toString() {
		List<String> tempList = new ArrayList<String>();
		tempList.add("account");
		tempList.add(getAccount());
		tempList.add("pwd");
		tempList.add(getPwd());
		tempList.add("type");
		tempList.add(getType());
		return bulidJson(tempList);
	}

	protected String bulidJson(List<String> paramsList) {
		if (paramsList == null || paramsList.size() == 0) {
			return "";
		}
		StringBuilder builder = new StringBuilder();
		builder.append("{");
		for (int i = 0; i < paramsList.size(); i += 2) {
			String key = paramsList.get(i);
			String value = paramsList.get(i + 1);
			if (i != 0) {
				builder.append(",");
			}
			builder.append("\"").append(key).append("\":\"").append(value).append("\"");
		}
		builder.append("}");
		return builder.toString();
	}
}
